
#ifndef _BFRUSTUM_H_
#define _BFRUSTUM_H_

#include <BBox>
#include <BSpace>
#include <BPlane>

namespace BWE
{
	template<class T = float>
	class IFrustumX
	{
	public:
		inline bool clip(const BVector& v) const
		{
			if (plane_near.clip(v))
				return true;
			if (plane_far.dist(v))
				return true;
			if (plane_left.dist(v))
				return true;
			if (plane_right.dist(v))
				return true;
			if (plane_top.dist(v))
				return true;
			if (plane_bottom.dist(v))
				return true;
			return false;
		}
		inline bool clip(const BBoxX<T>& box) const
		{
			if (plane_near.clip(box))
				return true;
			if (plane_far.clip(box))
				return true;
			if (plane_left.clip(box))
				return true;
			if (plane_right.clip(box))
				return true;
			if (plane_top.clip(box))
				return true;
			if (plane_bottom.clip(box))
				return true;
			return false;
		}
		inline bool clip(const BSpaceX<T>& space) const
		{
			if (clip(space.min()))
				return true;
			if (clip(space.max()))
				return true;
			if (clip(space.v0()))
				return true;
			if (clip(space.v1()))
				return true;
			if (clip(space.v2()))
				return true;
			if (clip(space.v3()))
				return true;
			if (clip(space.v4()))
				return true;
			if (clip(space.v5()))
				return true;
			if (clip(space.v6()))
				return true;
			if (clip(space.v7()))
				return true;
			return false;
		}

		BPlane				plane_near;
		BPlane				plane_far;
		BPlane				plane_left;
		BPlane				plane_right;
		BPlane				plane_top;
		BPlane				plane_bottom;
		BVector				near_v0;
		BVector				near_v1;
		BVector				near_v2;
		BVector				near_v3;
		BVector				far_v0;
		BVector				far_v1;
		BVector				far_v2;
		BVector				far_v3;
	};

	typedef IFrustumX<>		IFrustum;
}

#endif